"""
工具模块 - 包含一些辅助函数
"""

import streamlit as st
import os
# from museum_data_builder import build_museum_data
from modules.config import KNOWLEDGE_GRAPH_PATH, VECTOR_INDEX_FILE, DOCS_INFO_FILE, MUSEUM_DOCS_PATH

def check_required_files():
    """检查必要的文件是否存在"""
    return (
        os.path.exists(KNOWLEDGE_GRAPH_PATH) and 
        os.path.exists(VECTOR_INDEX_FILE) and 
        os.path.exists(DOCS_INFO_FILE) and
        len(os.listdir(MUSEUM_DOCS_PATH)) > 0
    )

# def rebuild_knowledge_base():
#     """重建知识库"""
#     with st.spinner("正在重建知识库..."):
#         try:
#             result = build_museum_data()
#             if all(result.values()):
#                 st.success("知识库重建成功！请刷新页面。")
#                 return True
#             else:
#                 st.error("知识库重建过程中出现错误。")
#                 return False
#         except Exception as e:
#             st.error(f"重建知识库过程出错: {str(e)}")
#             return False

def init_session_state():
    """初始化会话状态"""
    if 'current_artifact' not in st.session_state:
        st.session_state.current_artifact = None
    if 'chat_history' not in st.session_state:
        st.session_state.chat_history = []
    if 'page' not in st.session_state:
        st.session_state.page = "home"
    if 'api_key' not in st.session_state:
        st.session_state.api_key = os.environ.get("AI_STUDIO_API_KEY", "") 